package frontera;
import entidad.Movimientos;
import entidad.MovimientoDetalles;

import control.DetallesCTR;
import entidad.Factura;
import java.util.ArrayList;
import javax.swing.table.DefaultTableModel;

public class FacturaGUI extends javax.swing.JPanel {
    DetallesCTR _control_detalles = new DetallesCTR();
    ArrayList<MovimientoDetalles> _detalles = new ArrayList<MovimientoDetalles>() ;
    Factura _factura = new Factura();
    /** Creates new form FacturaGUI */
    public FacturaGUI() {
        initComponents();
    }

    public Factura get_factura() {
        return _factura;
    }

    public void set_factura(Factura _factura) {
        this._factura = _factura;

        for(Movimientos _movimiento : _factura.get_movimiento() ){
            for(MovimientoDetalles _iterator_detalles : FramePrincipal1.sistema.getDetalles() ){
                if(_iterator_detalles.getMovimiento().equals( _movimiento ) ){
                    System.out.println("hola");

                    System.out.println(String.valueOf( _iterator_detalles.getCliente()) );
                    _detalles.add(_iterator_detalles);
                }
            }
        }
    }

    public void tabular(){
        cliente_lb.setText( _factura.get_movimiento().get(0).getClientes().getNombre() );
        cedula_lb.setText( String.valueOf(_factura.get_movimiento().get(0).getClientes().getCedula())     );
        factura_lb.setText( String.valueOf(_factura.getId()) );

        DefaultTableModel _data = new DefaultTableModel(new Object []{"Servicio","Cantidad","Vlr. Unitario","IVA","Vlr. Total" },0);
        int totalFactura = 0;
        String col1 = "";
        int col2 = 0;
        int col3 = 0;
        int col4 = 0;
        int col5 = 0;

        for(MovimientoDetalles _registro : _detalles){
                //liberando el servicio
                _registro.getServicios().setEstado(true);

                col1 = _registro.getServicios().getNombre();
                col2 = _registro.getServicios().getCantidad();
                col3 = _registro.getServicios().getValorUnitario();

                col4 = _registro.getServicios().getIva();
                col5 = _registro.getValorTotal();
                totalFactura += _registro.getValorTotal();
                _data.addRow(new Object []{col1,col2,col3,col4,col5}) ;
            }
           grid_factura.setModel(_data);

           
           total_lb.setText("$ "+Integer.toString(totalFactura));
    }


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        factura_lb = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        cliente_lb = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        cedula_lb = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        grid_factura = new javax.swing.JTable();
        jLabel9 = new javax.swing.JLabel();
        total_lb = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel3.setForeground(new java.awt.Color(0, 102, 51));
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("Factura No.");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel2.setForeground(new java.awt.Color(0, 102, 51));
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Sistema de Facturación Hotelero");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 24));
        jLabel7.setForeground(new java.awt.Color(0, 102, 51));
        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel7.setText("La Potra Hotel Campestre");

        factura_lb.setFont(new java.awt.Font("Courier New", 1, 18));
        factura_lb.setForeground(new java.awt.Color(255, 0, 0));
        factura_lb.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        factura_lb.setText("Factura");

        jLabel1.setText("Cliente");

        cliente_lb.setFont(new java.awt.Font("Tahoma", 1, 14));
        cliente_lb.setText("Cliente as das d sad sdas dafsad sad");

        jLabel6.setText("Cedula");

        cedula_lb.setFont(new java.awt.Font("Tahoma", 1, 14));
        cedula_lb.setText("85.524.178");

        grid_factura.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Servicio", "Cantidad", "Vlr. Unitario", "IVA", "Vlr. Total"
            }
        ));
        grid_factura.setGridColor(new java.awt.Color(204, 204, 204));
        jScrollPane1.setViewportView(grid_factura);

        jLabel9.setText("Valor Total");

        total_lb.setFont(new java.awt.Font("Tahoma", 1, 14));
        total_lb.setText("85.524.178");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(cliente_lb)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 55, Short.MAX_VALUE)
                .addComponent(jLabel6)
                .addGap(18, 18, 18)
                .addComponent(cedula_lb)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(111, 111, 111)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(88, 88, 88))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(factura_lb, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 485, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(346, Short.MAX_VALUE)
                .addComponent(jLabel9)
                .addGap(18, 18, 18)
                .addComponent(total_lb)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(factura_lb))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cliente_lb)
                    .addComponent(jLabel6)
                    .addComponent(cedula_lb))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(total_lb))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel cedula_lb;
    private javax.swing.JLabel cliente_lb;
    private javax.swing.JLabel factura_lb;
    private javax.swing.JTable grid_factura;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel total_lb;
    // End of variables declaration//GEN-END:variables

}
